package com.bjpowernode.style;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 线程创建方式三：实现Callable接口，实现call()方法
 */
public class Test03 implements Callable<String> {

    @Override
    public String call() throws Exception {
        return "Thread execute.txt finished";
    }

    public static void main(String[] args) {
        //创建线程
        FutureTask<String> futureTask = new FutureTask(new Test03());
        //启动线程
        new Thread(futureTask).start();

        try {
            //等待任务执行完毕，并返回结果
            String result = futureTask.get();

            System.out.println(result);

        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }

        //main线程执行
        System.out.println("main方法执行");
    }
}
